﻿
/**
 * 获取对象的工厂类
 * @return {void}
 */
function ObjectFactory(){
	
}

ObjectFactory.prototype = {
	/**
	 * 判断一个对象是否为空
	 * @param {Object} obj
	 */
	isNull:function(obj){
		if("undefined" == obj || null == obj || "" == obj ){
			return true;
		}
		return false;
	},
	getBrowserInfo:function(){
		var Browser = {};
		var ua = window.navigator.userAgent;
		Browser.platform = window.navigator.platform;
		Browser.opera = typeof(window.opera)=="object";
		
		var re = null;
		if(Browser.opera) re = /Opera(\s|\/)(\d+(\.\d+)?)/;
		
		if(!Browser.opera && ua.indexOf("MSIE")>0){
			Browser.ie = true;
			Browser.name = "ie";
			re = /MSIE( )(\d+(\.\d+)?)/;
		}else if(ua.indexOf("Firefox")>0){
			Browser.firefox = true;
			Browser.name = "firefox";
			re = /Firefox(\s|\/)(\d+(\.\d+)?)/;
		}else if(ua.indexOf("Safari")>-1){
			Browser.safari = true;
			Browser.name = "safari";
			re = /Version(\/)(\d+(\.\d+)?)/;
		}else if(window.navigator.product == "Gecko"){
			Browser.mozilla = true;
			Browser.name = "mozilla";
			re = /rv(\:)(\d+(\.\d+)?)/;
		}else if(window.navigator.vendor == "Netscape"){
			Browser.netscape= true;
			Browser.name = "netscape";
			re = /Netscape(\s|\/)(\d+(\.\d+)?)/;
		}

		if("undefined"!=typeof(re) && re.test(ua))
			Browser.version = parseFloat(RegExp.$2);
		
		 return Browser;
	},
	/**
	 * 根据元素的标记获取元素对象
	 * 获取对象的方法有：
	 * 		1.通过元素id获取(一个对象)：document.getElementById(id);
	 * 		2.通过元素name获取(名称相同的对象数组)：document.getElementsByName(name);
	 * 		3.通过访问document的所有子元素获取(只能在IE浏览器里使用)：document.all[flag];
	 * @param {String} flag 元素的标记
	 */
	getElement:function(flag){
		var element = document.getElementById(flag);
		if(this.isNull(element)){
			element = document.getElementsByName(flag)[0];
		}
		return element;
	},
	/**
	 * 获取元素对象的属性值
	 * 		获取固有属性值：对象.属性
	 * 		获取用户自定义属性值：对象.getAttribute(属性名称)
	 * @param {String} 属性值
	 */
	getAttriubte:function(element,attributeName){
		var value = eval(element.attributeName);
		if(this.isNull(element)){
			value = element.getAttribute(attributeName);
		}
		return value;
	},
	/**
	 * 获取事件的触发对象
	 */
	getElementByEvent:function(){
		 return event.srcElement ? event.srcElement:event.target;
	},
	/**
	 * 获取form的对象
	 * @param {String} name form的名称
	 */
	getForm:function(name){
		if(!this.isNull(name)){
			return document.forms[name];
		}
		return document.forms[0];
	},
	/**
	 * 获取父窗口对象：模态窗口或弹出窗口对象
	 * window.dialogArguments是模态窗口的标记
	 */
	getParent:function(){
		return (window.dialogArguments) ? window.dialogArguments : window.opener;
	},
	/**
	 * 根据frame的名称获取frame对象
	 */
	getFrame:function(name){
		return window.frames[name];
	},
	/**
	 * 获取模态窗口对象
	 * @param {String} url
	 * @param {Object} dialogArguments 参数(在模态窗口里通过window.dialogArguments获取)
	 * @param {int} width 模态窗口的宽度
	 * @param {int} height 模态窗口的高度
	 * @return {Object} dialogValue(在模态窗口里通过 window.returnValue = "" 返回)
	 */
	getModalDialog:function(url,dialogArguments,width,height){
		var dialogValue = window.showModalDialog(url + "&rnd=" + Math.random(),
				dialogArguments,"dialogWidth:" + dialogWidth + "px;dialogHeight:" + dialogHeight + ";center:yes;status:no;help:no;scroll:no");
		if(typeof(dialogValue) != 'undefined' && dialogValue != null){
			return dialogValue;
		}
		return "";
	},
	/**
	 * 获取弹出窗口对象
	 * @param {String} url
	 * @param {int} width 窗口的宽度
	 * @param {int} height 窗口的高度
	 */
	getWindow:function(url,width,height,name){
		var _height = (height!=null) ? height : "400";
		var	_width = (width != null) ? width : "600";
		var _name = (name!=null) ? name : "select";

		var topHeight=(window.screen.height-_height)/2;
		var leftWidth=(window.screen.width-_width)/2;

		var win = window.open(url,_name,'height='+_height+',width='+_width+',top='+topHeight+',left='+leftWidth+',alwaysRaised=yes,depended=yes,titlebar=yes,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no,z-look=yes');		
		return win;
	},
	/**	 
	 * 打开全屏窗口
	 */	
	getFullScreenWindow:function(url,name){
		var name = (name!=null) ? name : "fullScreen";
		var win = window.open(url,name,"titlebar=yes,location=no,status=no,toolbar=no,resizable=yes,menubar=no,width="+screen.availWidth+",height="+screen.availHeight+",top=0,left=0");		
		win.moveTo(0,0);   
		win.resizeTo(screen.availWidth,screen.availHeight);   
		win.outerWidth=screen.availWidth;   
		win.outerHeight=screen.availHeight;
		win.resizable=0;
		return win;
	}
}